package com.zzzmode.httpjob.web.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zl on 2014/12/7.
 */
public class ApiError implements Serializable {

    private static final Map<Integer,String> COMMON_ERROR_MAP=new HashMap<>();
    static {
        COMMON_ERROR_MAP.put(-1,"Unknown error");
        COMMON_ERROR_MAP.put(0,"Ok");
        COMMON_ERROR_MAP.put(1,"Paramter Invalid"); //请求参数无效
        COMMON_ERROR_MAP.put(2,"Authenticate Invalid");  //认证无效
        COMMON_ERROR_MAP.put(3,"Operate Invalid"); //操作无效

        COMMON_ERROR_MAP.put(100,"Not Find");
    }




    private int code;
    private String msg;
    private long time;

    public ApiError(int code, String msg, long time) {
        this.code = code;
        this.msg = msg;
        this.time = time;
        if(msg == null){
            msg=COMMON_ERROR_MAP.get(-1);
        }
    }

    public ApiError(int code, String msg) {
        this(code,msg,System.currentTimeMillis());
    }

    public ApiError(int code) {
        this(code,COMMON_ERROR_MAP.get(code));
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }
}
